
package View;

import Client.Client;
import Module.Session;
import Module.addUserRoles;
import Module.User;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import Module.addUserRoles;

/**
 *
 * @author CCD gruppe 2
 */
class TeamSessionInfoPanel extends JPanel{

    private javax.swing.JCheckBox customerCheckBox;
    private javax.swing.JCheckBox facilitatorCheckBox;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JCheckBox secretaryCheckBox;
    private javax.swing.JLabel sessionDeliveranceForTeamLabel;
    private javax.swing.JLabel sessionGoalForTeamLabel;
    private JTextArea goalForTeamTextArea;
    private JTextArea deliveranceForTeamTextArea;
    private JList teamMemberList;
    private DefaultListModel teamMemberListModel;
    private ArrayList<addUserRoles> userRoles = new ArrayList<addUserRoles>();
    private ArrayList<User> users = new ArrayList<User>();
    private String selectedUser;

    public TeamSessionInfoPanel(){
        initComponents();
    }

    public void initComponents(){

        teamMemberListModel = new DefaultListModel();
        customerCheckBox = new JCheckBox();
        facilitatorCheckBox = new JCheckBox();
        jLabel15 = new JLabel();
        jScrollPane12 = new JScrollPane();
        jScrollPane13 = new JScrollPane();
        jScrollPane14 = new JScrollPane();
        secretaryCheckBox = new JCheckBox();
        sessionDeliveranceForTeamLabel = new JLabel();
        sessionGoalForTeamLabel = new JLabel();
        goalForTeamTextArea = new JTextArea();
        deliveranceForTeamTextArea = new JTextArea();
        teamMemberList = new JList();
        teamMemberList.setModel(teamMemberListModel);

        goalForTeamTextArea.setColumns(20);
        goalForTeamTextArea.setLineWrap(true);
        goalForTeamTextArea.setRows(5);
        jScrollPane12.setViewportView(goalForTeamTextArea);

        sessionGoalForTeamLabel.setText("Sesjonsmål for team:");

        jLabel15.setText("Teammedlemmer:");

        customerCheckBox.setText("Kunde");

        sessionDeliveranceForTeamLabel.setText("Sesjonsleveranse for team:");


        jScrollPane13.setViewportView(teamMemberList);

        facilitatorCheckBox.setText("Fasilitator");

        deliveranceForTeamTextArea.setColumns(20);
        deliveranceForTeamTextArea.setLineWrap(true);
        deliveranceForTeamTextArea.setRows(5);
        jScrollPane14.setViewportView(deliveranceForTeamTextArea);

        secretaryCheckBox.setText("Sekretær");



        org.jdesktop.layout.GroupLayout expertGroupPanelLayout = new org.jdesktop.layout.GroupLayout(this);
        setLayout(expertGroupPanelLayout);
        expertGroupPanelLayout.setHorizontalGroup(
            expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(expertGroupPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel15)
                    .add(jScrollPane13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(secretaryCheckBox)
                    .add(customerCheckBox)
                    .add(facilitatorCheckBox))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jScrollPane14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, sessionDeliveranceForTeamLabel)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, sessionGoalForTeamLabel)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
                .addContainerGap())
        );
        expertGroupPanelLayout.setVerticalGroup(
            expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 359, Short.MAX_VALUE)
            .add(expertGroupPanelLayout.createSequentialGroup()
                .add(8, 8, 8)
                .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(sessionGoalForTeamLabel)
                    .add(expertGroupPanelLayout.createSequentialGroup()
                        .add(jLabel15)
                        .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(expertGroupPanelLayout.createSequentialGroup()
                                .add(expertGroupPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(expertGroupPanelLayout.createSequentialGroup()
                                        .add(4, 4, 4)
                                        .add(customerCheckBox)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(facilitatorCheckBox)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(secretaryCheckBox))
                                    .add(expertGroupPanelLayout.createSequentialGroup()
                                        .add(8, 8, 8)
                                        .add(jScrollPane12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(sessionDeliveranceForTeamLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jScrollPane14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(expertGroupPanelLayout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jScrollPane13)))))
                .addContainerGap())
        );
    }

    public JCheckBox getCustomerCheckBox() {
        return customerCheckBox;
    }

    public JCheckBox getFacilitatorCheckBox() {
        return facilitatorCheckBox;
    }

    public JTextArea getGoalForTeamTextArea() {
        return goalForTeamTextArea;
    }

    public JLabel getjLabel15() {
        return jLabel15;
    }

    public JScrollPane getjScrollPane12() {
        return jScrollPane12;
    }

    public JScrollPane getjScrollPane13() {
        return jScrollPane13;
    }

    public JScrollPane getjScrollPane14() {
        return jScrollPane14;
    }

    public JCheckBox getSecretaryCheckBox() {
        return secretaryCheckBox;
    }

    public JLabel getSessionDeliveranceForTeamLabel() {
        return sessionDeliveranceForTeamLabel;
    }

    public JLabel getSessionGoalForTeamLabel() {
        return sessionGoalForTeamLabel;
    }

    public JList getTeamMemberList() {
        return teamMemberList;
    }

    public DefaultListModel getTeamMemberListModel() {
        return teamMemberListModel;
    }

    public JTextArea getDeliveryTeamTextArea(){
        return deliveranceForTeamTextArea;
    }

    public int getIndexUserRoles(String u){
        for(int i=0;i<userRoles.size();i++){
            if(userRoles.get(i).getUser().getFullname().equals(u)){
                return i;
            }
        }
        return -1;
    }

        public void updateUserRoles(Client client,int sessionId, int teamId){
        userRoles.clear();
        ArrayList<User> user = client.getUsersToTeam(teamId);
        for(User u : user){
            ArrayList<String> roles = client.getRoleToUserSession(u.getId(), sessionId);
            addUserRoles addUserRoles = new addUserRoles(u, false,false,false);
            for(int i=0; i<roles.size(); i++){
                if(roles.get(i).equals("Fasilitator"))addUserRoles.setFasilitator(true);
                if(roles.get(i).equals("Sekretær"))addUserRoles.setSecretary(true);
                if(roles.get(i).equals("Kunde"))addUserRoles.setCustomer(true);
            }
            userRoles.add(addUserRoles);


    }
}

    public void isInfoPanel(){
        goalForTeamTextArea.setFocusable(false);
        deliveranceForTeamTextArea.setFocusable(false);
        secretaryCheckBox.setEnabled(false);
        facilitatorCheckBox.setEnabled(false);
        customerCheckBox.setEnabled(false);

    }
    public void editButtonPressed(){
        goalForTeamTextArea.setFocusable(true);
        deliveranceForTeamTextArea.setFocusable(true);
        secretaryCheckBox.setEnabled(true);
        facilitatorCheckBox.setEnabled(true);
        customerCheckBox.setEnabled(true);
    }

    public ArrayList<addUserRoles> getUserRoles() {
        return userRoles;
    }

    public ArrayList<User> getUsers() {
        return users;
    }
    public void setSelectedUser(String userName){
        selectedUser = userName;
    }

    public String getSelectedUser(){
        return selectedUser;
    }

    public void setUserRoles(ArrayList<addUserRoles> userRoles) {
        this.userRoles = userRoles;
    }

}
